package com.evil.kingdom.controller.person.base;

import com.evil.common.core.entity.R;
import com.evil.kingdom.pojo.entity.person.base.Person;
import com.evil.kingdom.service.person.base.PersonService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author liyang
 * @date 2024-05-22 17:11
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/person")
public class PersonController {

    private final PersonService personService;

    /**
     * 初始化人物
     *
     * @return R
     */
    @RequestMapping("/init")
    public R<String> init(String suffix) {
        personService.init(suffix);
        return R.success();
    }

    /**
     * 注册新人物
     *
     * @param person person
     * @return R
     */
    @PostMapping("/register")
    public R<Person> register(@RequestBody @Validated Person person) {
        person.setLevel(1);
        person.setExperience(1);
        person.setArm(null);
        person.setItem(null);
        person.setMount(null);
        return R.success(personService.add(person));
    }

    /**
     * 新增人物
     *
     * @param person person
     * @return R
     */
    @PostMapping("/add")
    public R<Person> add(@RequestBody @Validated Person person) {
        return R.success(personService.add(person));
    }
}
